package com.mrdeer.iot.bean.command;

import com.mrdeer.iot.constant.FrameConst;
import com.mrdeer.iot.utils.HexHelper;
import lombok.Data;

/**
 * 物联网指令构造器
 *
 * @Author: xie jianchu
 */
@Data
public class InstructionBuilder {

    public static String buildInstruction(Protocol protocol, String commandStr, String type) {
        StringBuilder sb = new StringBuilder();
        sb.append(protocol.getHeader());
        sb.append(protocol.getCode());
        sb.append(protocol.getVersion());
        sb.append(HexHelper.numToHex8(commandStr.length() / 2 + 7));
        sb.append(protocol.getDest());
        sb.append(type);
        sb.append(commandStr);
        sb.append(protocol.getCrc());
        return sb.toString();
    }


    private String header = HexHelper.numToHex8(FrameConst.header);

    private String code;

    private String version;

    private String length;

    private String address;

    private String type;

    private String data;

    private String crc;

}
